import eventClient
import testbedReservation
import time
import getopt, sys


#This code to push data and add an event to a calendar isn't complete.
#Intention was to use "output_event" for the data needed by the
#caldavclientlibrary.client.clientsession.writeData() fxn

class PutEvent:

	def __init__(self, start, end):
		#start and end are strings in format "yyyymmdd'T'hhmmss'Z'"
		self.startInfo = start
		self.endInfo = end

	def output_event(self, summary="", description=""):
		eventtxt = "BEGIN:VCALENDAR\nBEGIN:VEVENT\n"
		uid = str(time.time()).split('.')[0]
		eventtxt = eventtxt + "UID:" + uid + "\n"
		eventtxt = eventtxt + "DTSTART:" + self.startInfo + "\n"
		eventtxt = eventtxt + "DTEND:" + self.endInfo + "\n"
		eventtxt = eventtxt + "SUMMARY:" + summary + "\n"
		eventtxt = eventtxt + "DESCRIPTION:" + description + "\n"
		eventtxt = eventtxt + "END:VEVENT\nEND:VCALENDAR\n\n"
		return eventtxt
		

if __name__ == "__main__":
	options, args = getopt.getopt(sys.argv[1:], "", ["user=","passwd=","url=","start=","end=","hosts=","images"])
	options = dict(options)
	if not "--url" in options:
		options["--url"] = raw_input("Enter url (include http:..) ")
	#the url for events needs to end in '/'
	if not options["--url"].endswith("/"):
		options["--url"] += "/"
	if not "--user" in options:
		options["--user"] = raw_input("Enter user name: ")
	if not "--passwd" in options:
		options["--passwd"] = getpass.getpass()
	if not "--start" in options:
		options["--start"] = raw_input("Enter start date/time in format yyyymmdd'T'hhmmss ")
	while True:
		try:
			time.strptime(options["--start"], "%Y%m%dT%H%M%S")
		except ValueError:
			print "The format for start date/time did not follow yyyymmdd'T'hhmmss"
			options["--start"] = raw_input("Enter start date/time in format yyyymmdd'T'hhmmss ")
			continue
		break
	if not "--end" in options:
		options["--end"] = raw_input("Enter end date/time in format yyyymmdd'T'hhmmss ")
	while True:
		try:
			time.strptime(options["--end"], "%Y%m%dT%H%M%S")
		except ValueError:
			print "The format for end date/time did not follow yyyymmdd'T'hhmmss"
			options["--end"] = raw_input("Enter end date/time in format yyyymmdd'T'hhmmss ")
			continue
		break
